package com.sec.etech.org.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sec.etech.org.service.OrgUserSyncHrsService;
import org.openbpm.base.api.aop.annotion.CatchErr;
import org.openbpm.base.api.response.impl.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

@RestController
@RequestMapping("/orgUserSyncHrs")
@CrossOrigin
public class OrgUserSyncHrsController {
    @Autowired
    OrgUserSyncHrsService orgUserSyncHrsService;

    @PostMapping("/del")
    @CatchErr
    @Transactional
    public ResultMsg<Boolean> del(@RequestParam String list) throws UnsupportedEncodingException {
        String decode = URLDecoder.decode(list, "utf-8");
        JSONArray jsonArray = JSONObject.parseArray(decode);
        return orgUserSyncHrsService.del(jsonArray);
    }

    @PostMapping("/diff")
    public ResultMsg<Boolean> diff() {
        return orgUserSyncHrsService.diff();
    }

    @PostMapping("/sync")
    public ResultMsg<Boolean> sync() {
        return orgUserSyncHrsService.sync();
    }
}

